<?php
require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'check_user_login.php';
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . 'dao_user.php';

$dao_user = new dao_user();

if ($_SERVER['REQUEST_METHOD'] == "POST"){
    if($dao_user->login('admin', $_POST['txt_old_passsword'])){
        if ($_POST['txt_new_passsword'] == $_POST['txt_retype_passsword']) {
            if($dao_user->set_admin_password($_POST['txt_new_passsword'])){ ?>
            <script type="text/javascript">
                alert("Set new password successfully!");
            </script>        
            <?php 
            } else {
                ?>
                <script type="text/javascript">
                    alert("Set new password successfully!");
                </script>
                <?php
            }
        } else {
            ?>
            <script type="text/javascript">
                alert("Retype password mismatch!");
            </script>
            <?php
        }
    } else {
        ?>
        <script type="text/javascript">
            alert("Old password isn't correct!");
        </script>
        <?php
    }
}

?>
<!DOCTYPE html>
<html>
<head id="Head1">
    <title>
        Change Password - Tesdo Admin
    </title>
    <?php
    require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php';
    ?>
</head>
<body>
    <?php
    require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'header.php';
    ?>


    <div>
        <div class="content-box-outer">
            <div class="content-box-right">
            </div>
            <div class="content-box-left">
                <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" id="form_change_pass" method="POST" enctype="multipart/form-data">
                    <h1>Change Password</h1>
                    <label>Old Password: </label>
                    <input type="password" name="txt_old_passsword" id="txt_old_passsword" placeholder="Old Password" required />
                    <br/>
                    <br/>
                    <label for="txt_new_passsword">New Password: </label>
                    <input type="password" name="txt_new_passsword" id="txt_new_passsword" placeholder="New Password" required />
                    <br/>
                    <br/>
                    <label for="txt_retype_passsword">Retype New Password: </label>
                    <input type="password" name="txt_retype_passsword" id="txt_retype_passsword" placeholder="Retype New Password" required />
                    <br/>
                    <br/>
                    <input type="submit" value="Change Password" name="btn_submit" id="btn_submit">
                </form>
            </div>
        </div>
    </div>

    <?php
    require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'footer.php';
    ?>
</body>
</html>
